import { createStore } from 'vuex'

export default createStore({
  state: {
    userLocation:null,
    userCityName:null,
    user: JSON.parse(sessionStorage.getItem('user')),
    token: sessionStorage.getItem('token')
  },
  getters: {
  },
  mutations: {
    getUserLocation(state,userLngLat){
      state.userLocation=userLngLat
    },
    getCityName(state,city){
      state.userCityName=city
    },
    updateUser(state, payload) {
      state.user = payload
      sessionStorage.setItem('user',JSON.stringify(payload))
    },
    saveToken(state, token) {
      state.token = token
      sessionStorage.setItem('token', token)
    }
  },
  actions: {
    loginAndSaveUser(store, payload) {
      store.commit('updateUser', {user_id: x, user_name: '测试用户'})
    }
  },
  modules: {
  }
})
